﻿namespace WMS6.BLL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.IDAL;
    using WMS6.QueryEntity;
    using WMS6.DALFactory;

    public class PickDetailBLL
    {
        private static readonly ICommonMethodDA commonMethod = DataAccess.CreateCommonMethod();
        private List<string> dataBaseID;
        private static readonly IPickDetailDA pickDetailDA = DataAccess.CreatePickDetailDA();
        private PubParasInfo pubParasInfo;

        public PickDetailBLL()
        {
            this.pubParasInfo = null;
        }

        public PickDetailBLL(string currentWH)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(currentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(currentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001");
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002");
            }
        }

        public PickDetailBLL(PubParasInfo tempPubParasInfo)
        {
            this.pubParasInfo = null;
            if (!string.IsNullOrEmpty(tempPubParasInfo.CurrentWH))
            {
                this.dataBaseID = commonMethod.GetDataBaseID(tempPubParasInfo.CurrentWH);
                if (this.dataBaseID == null)
                {
                    PublicMethod.GetInstance().ShowAlertMessage("C001", this.pubParasInfo.UserLanguage);
                }
                else
                {
                    this.pubParasInfo = new PubParasInfo();
                    this.pubParasInfo = tempPubParasInfo;
                }
            }
            else
            {
                PublicMethod.GetInstance().ShowAlertMessage("C002", this.pubParasInfo.UserLanguage);
            }
        }

        public DataSet GetPickDetailInfoByQueryEntity(PickDetailQueryEntity pickDetailQueryEntity)
        {
            List<string> sqlWhere = new List<string>();
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.OrderID))
            {
                sqlWhere.Add(" PD.ORDER_ID " + pickDetailQueryEntity.OrderID);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.OrderLineID))
            {
                sqlWhere.Add(" PD.ORDER_LINE_ID " + pickDetailQueryEntity.OrderLineID);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.OwnerID))
            {
                sqlWhere.Add(" PD.OWNER_ID " + pickDetailQueryEntity.OwnerID);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.SkuID))
            {
                sqlWhere.Add(" PD.SKU_ID " + pickDetailQueryEntity.SkuID);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.Status))
            {
                sqlWhere.Add(" PD.STATUS " + pickDetailQueryEntity.Status);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.ExternOrderID))
            {
                sqlWhere.Add(" OD.EXTERN_ORDER_ID " + pickDetailQueryEntity.ExternOrderID);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.Lot))
            {
                sqlWhere.Add(" PD.LOT " + pickDetailQueryEntity.Lot);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.FromLoc))
            {
                sqlWhere.Add(" PD.LOC " + pickDetailQueryEntity.FromLoc);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.ToLoc))
            {
                sqlWhere.Add(" PD.TO_LOC " + pickDetailQueryEntity.ToLoc);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.LpnID))
            {
                sqlWhere.Add(" PD.LPN_ID " + pickDetailQueryEntity.LpnID);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.LotAttr01))
            {
                sqlWhere.Add(" LA.LOT_ATTR01 " + pickDetailQueryEntity.LotAttr01);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.LotAttr02))
            {
                sqlWhere.Add(" LA.LOT_ATTR02 " + pickDetailQueryEntity.LotAttr02);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.LotAttr03))
            {
                sqlWhere.Add(" LA.LOT_ATTR03 " + pickDetailQueryEntity.LotAttr03);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.LotAttr04))
            {
                sqlWhere.Add(" LA.LOT_ATTR04 " + pickDetailQueryEntity.LotAttr04);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.LotAttr05))
            {
                sqlWhere.Add(" LA.LOT_ATTR05 " + pickDetailQueryEntity.LotAttr05);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.LotAttr06))
            {
                sqlWhere.Add(" LA.LOT_ATTR06 " + pickDetailQueryEntity.LotAttr06);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.LotAttr07))
            {
                sqlWhere.Add(" LA.LOT_ATTR07 " + pickDetailQueryEntity.LotAttr07);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.LotAttr08))
            {
                sqlWhere.Add(" LA.LOT_ATTR08 " + pickDetailQueryEntity.LotAttr08);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.LotAttr09))
            {
                sqlWhere.Add(" LA.LOT_ATTR09 " + pickDetailQueryEntity.LotAttr09);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.LotAttr10))
            {
                sqlWhere.Add(" LA.LOT_ATTR10 " + pickDetailQueryEntity.LotAttr10);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.ExternalLot))
            {
                sqlWhere.Add(" LA.EXTERNAL_LOT " + pickDetailQueryEntity.ExternalLot);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.VendorID))
            {
                sqlWhere.Add(" LA.VENDOR_ID " + pickDetailQueryEntity.VendorID);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.WaveID))
            {
                sqlWhere.Add(" WD.WAVE_ID " + pickDetailQueryEntity.WaveID);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.ProduceDate))
            {
                sqlWhere.Add(pickDetailQueryEntity.ProduceDate.Replace("@ProduceDate@", " LA.PRODUCE_DATE "));
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.ExpiryDate))
            {
                sqlWhere.Add(pickDetailQueryEntity.ExpiryDate.Replace("@ExpiryDate@", " LA.EXPIRY_DATE "));
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.ReceiptDate))
            {
                sqlWhere.Add(pickDetailQueryEntity.ReceiptDate.Replace("@ReceiptDate@", " LA.RECEIPT_DATE "));
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.ReferenceNum))
            {
                sqlWhere.Add(" OD.REFERENCE_NUM " + pickDetailQueryEntity.ReferenceNum);
            }
            if (!string.IsNullOrEmpty(pickDetailQueryEntity.LocCategory))
            {
                sqlWhere.Add(" L.LOC_CATEGORY " + pickDetailQueryEntity.LocCategory);
            }
            return pickDetailDA.GetPickDetailByQueryList(sqlWhere, pickDetailQueryEntity, this.dataBaseID[0], this.pubParasInfo);
        }
    }
}

